package main

import "fmt"

type ServerConfig struct {
	Port int
	Timeout int
}

type Option func(*ServerConfig)

func WithPort(port int) Option {
	return func(cfg *ServerConfig) {
		cfg.Port = port
	}
}

func WithTimeout(timeout int) Option {
	return func(cfg *ServerConfig) {
		cfg.Timeout = timeout 
	}
}

func NewServer(options ...Option) *ServerConfig{
	cfg := &ServerConfig {
		Port: 8080,
		Timeout: 30,
	}

	for _, opt := range options {
		opt(cfg)
	}

	return cfg
}

func main() {
	server := NewServer( 
		WithPort(9090),
		WithTimeout(60),
	)
	fmt.Printf("Server Port: %d, Timeout: %d\n", server.Port, server.Timeout);

	server1 := NewServer()
	fmt.Printf("Server Port: %d, Timeout: %d\n", server1.Port, server1.Timeout);
}

